package cn.sx.dao;

/*
 *@program:sx_emall_ssm
 *@author: sx
 *@desc: user接口
 *@Time: 2020/9/17  10:17
 */

import cn.sx.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserDao {

    /*查询所有的方法*/
    @Select("select * from users order by id")
    List<User> queryAllRecords();


    /*获取总数*/
    @Select("select count(*) from users")
    public long selectCount();

    @Select("seLect * from users order by id desc limit #{begin} ，#{size}")
    public List<User> selectList (@Param("begin")int begin, @Param("size")int size);

    /*根据id查询*/
    @Select("select * from users where id = #{id}")
    public User select(int id);

    /*根据用户名查询(验证)*/
    @Select("select * from users where username = #{username}")
    public User selectByUsername(String username);

    /*根据用户名和密码查询（登录）*/
    @Select("select * from users where username=#{username} and password=#{password}")
    public User selectByUsernameAndPassword(@Param("username") String username,
                                            @Param("password") String password);

    /*注册*/
    @Insert("INSERT INTO users (`username`,`password`,`name`,`phone`,`address`) VALUE(#{username},#{password},#{name},#{phone},#{address})")
    /*加密密码*/
    @SelectKey(keyProperty = "id",statement = "SELECT LAST_INSERT_ID()",before = false,resultType = Integer.class)
    public boolean insert(User user);
    /*修改收货地址*/
    @Update("UPDATE users SET `name`=#{name},phone=#{phone},address=#{address} WHERE id=#{id}")
    public boolean updateAddress(User user);
    /*修改密码*/
    @Update("update users set password=#{password} where id =#{id}")
    public boolean updatePassword(@Param("id") int id, @Param("password") String password);
    /*删除用户*/
    @Delete("delete from users where id=#{id}")
    int deleteUser(int id);
}
